package com.ymatou.iapi.csim.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetStatusBean;
import com.ymatou.iapi.csim.service.GetStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*获取客服状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetStatus{
	private static GetStatusBean getstatusBean;
	private static GetStatusCall getstatusCall;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取客服状态");
	}

	@Before
	public void caseUp() {
		getstatusBean=new GetStatusBean();
		getstatusCall=new GetStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_001() {
		Logger.start(true,"获取客服状态-在线");
		try {
			ymt_onlinecs onlinecs1 =service.getOnlineCS(csId);
			
			getstatusBean.setCsId(csId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();	
			//
			Logger.verifyEquals("200", getstatusCall.getStatus(), "验证Status");
			Logger.verifyEquals("", getstatusCall.getMsg(), "验证Msg");
			Logger.verifyEquals(true, getstatusCall.getResult().getBoolean("Success"), "验证Success");
			
			ymt_onlinecs onlinecs2 =onlinecsWapper.selectBy(MapUtil.hashMap("CSId",getstatusBean.getCsId())).get(0);
			Logger.verifyEquals(onlinecs2.getMaxSessions(), getstatusCall.getResult().getInt("MaxSessionCount"), "验证MaxSessionCount");
			Logger.verifyEquals(onlinecs2.getStatus(), getstatusCall.getResult().getInt("Status"), "验证Status");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_002() {
		Logger.start(true,"获取客服状态-离线");
		try {
			ymt_onlinecs onlinecs1 =service.getOnlineCS(csId);
			onlinecs1.setStatus(1);
			onlinecsWapper.updateByPrimaryKey(onlinecs1);
			
			getstatusBean.setCsId(csId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();	
			
			Logger.verifyEquals("200", getstatusCall.getStatus(), "验证Status");
			Logger.verifyEquals("", getstatusCall.getMsg(), "验证Msg");
			Logger.verifyEquals(true, getstatusCall.getResult().getBoolean("Success"), "验证Success");
			
			ymt_onlinecs onlinecs2 =onlinecsWapper.selectBy(MapUtil.hashMap("CSId",getstatusBean.getCsId())).get(0);
			Logger.verifyEquals(onlinecs2.getMaxSessions(), getstatusCall.getResult().getInt("MaxSessionCount"), "验证MaxSessionCount");
			Logger.verifyEquals(onlinecs2.getStatus(), getstatusCall.getResult().getInt("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_003() {
		Logger.start(true,"获取客服状态-不存在");
		try {
			ymt_onlinecs onlinecs1 =service.getOnlineCS(csId);
			onlinecsWapper.deleteBy(MapUtil.hashMap("CSId",onlinecs1.getCSId()));
			
			getstatusBean.setCsId(csId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();	
			
			Logger.verifyEquals("200", getstatusCall.getStatus(), "验证Status");
			Logger.verifyEquals("", getstatusCall.getMsg(), "验证Msg");
			Logger.verifyEquals(true, getstatusCall.getResult().getBoolean("Success"), "验证Success");

			Logger.verifyEquals(10, getstatusCall.getResult().getInt("MaxSessionCount"), "验证MaxSessionCount");
		    Logger.verifyEquals(-1, getstatusCall.getResult().getInt("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}